﻿/*
 * Author: Alexander Sjösten
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Final_Project.SessionData;

namespace Final_Project.CustomerData
{
    /// <summary>
    /// This class represents an InvoiceCustomer.
    /// </summary>
    [Serializable()]
    public class InvoiceCustomer : Customer, ISerializable
    {
        // Local variables
        private string street;
        private string zip;
        private string city;

        /// <summary>
        /// Constructor for InvoiceCustomer taking 0 parameters,
        /// will chain call next constructor
        /// </summary>
        public InvoiceCustomer()
            : this(string.Empty) { }

        /// <summary>
        /// Constructor for InvoiceCustomer taking 1 parameter,
        /// will chain call next constructor
        /// </summary>
        /// <param name="street">The name of the street to send the invoice</param>
        public InvoiceCustomer(string street)
            : this(street, string.Empty) { }

        /// <summary>
        /// Constructor for InvoiceCustomer taking 2 parameters,
        /// will chain call next constructor
        /// </summary>
        /// <param name="street">The name of the street to send the invoice</param>
        /// <param name="zip">The zip code of the city to send the invoice to</param>
        public InvoiceCustomer(string street, string zip)
            : this(street, zip, string.Empty) { }
        
        /// <summary>
        /// Constructor for InvoiceCustomer taking 4 parameters,
        /// will chain call next constructor
        /// </summary>
        /// <param name="street">The name of the street to send the invoice</param>
        /// <param name="zip">The zip code of the city to send the invoice to</param>
        /// <param name="city">The city the invoice will be sent to</param>
        public InvoiceCustomer(string street, string zip, string city)
            : this(string.Empty, string.Empty, string.Empty, string.Empty, street, zip, city, 0, new List<TreatmentSession>()) { }

        /// <summary>
        /// Constructor for InvoiceCustomer taking 10 parameters,
        /// will call base constructor with 6 of the 10 parameters
        /// </summary>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="phoneNbr">The phone number of the customer</param>
        /// <param name="email">The email address of the customer</param>
        /// <param name="street">The name of the street to send the invoice</param>
        /// <param name="zip">The zip code of the city to send the invoice to</param>
        /// <param name="city">The city the invoice will be sent to</param>
        /// <param name="id">The ID of the customer</param>
        /// <param name="sessions">The list containing all the sessions for the customer</param>
        public InvoiceCustomer(string firstName, string lastName, string phoneNbr, string email, string street, string zip, string city, int id, List<TreatmentSession> sessions)
            : base(id, firstName, lastName, phoneNbr, email, sessions)
        {
            this.street = street;
            this.zip = zip;
            this.city = city;
        }

        /// <summary>
        /// Copy constructor for the InvoiceCustomer
        /// </summary>
        /// <param name="customer">The InvoiceCustomer to copy the data from</param>
        public InvoiceCustomer(InvoiceCustomer customer)
            : base((Customer)customer)
        {
            street = customer.Street;
            zip = customer.Zip;
            city = customer.City;
        }


        /// <summary>
        /// Constructor to help change the type from Customer to InvoiceCustomer,
        /// it will be cleaner then doing typecasts everywhere. :-)
        /// </summary>
        /// <param name="customer">The Customer that should be converted to a InvoiceCustomer</param>
        /// <param name="street">Street address to send the invoice to</param>
        /// <param name="zip">Zip code of the address to send the invoice to</param>
        /// <param name="city">City of the address to send the invoice to</param>
        public InvoiceCustomer(Customer customer, string street, string zip, string city)
            : base(customer.ID, customer.FirstName, customer.LastName, customer.Phone, customer.Email, customer.SessionsList)
        {
            this.street = street;
            this.zip = zip;
            this.city = city;
        }

        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">The information to the object from the deserialization</param>
        /// <param name="ctxt">The streaming context</param>
        public InvoiceCustomer(SerializationInfo info, StreamingContext ctxt)
            : base(info, ctxt)
        {
            street = (String)info.GetValue("StreetInfo", typeof(string));
            zip = (String)info.GetValue("ZipInfo", typeof(string));
            city = (String)info.GetValue("CityInfo", typeof(string));
        }

        /// <summary>
        /// Property for getting and setting the street name
        /// </summary>
        public string Street
        {
            get { return street; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    street = value;
                }
            }
        }

        /// <summary>
        /// Property for getting and setting the zip code
        /// </summary>
        public string Zip
        {
            get { return zip; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    zip = value;
                }
            }
        }

        /// <summary>
        /// Property for getting and setting the city name
        /// </summary>
        public string City
        {
            get { return city; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    city = value;
                }
            }
        }


        /// <summary>
        /// Property to get the entire address
        /// </summary>
        public string FullAddress
        {
            get { return Street + " " + Zip + " " + City; }
        }

        /// <summary>
        /// Method for serialization, must be added since it's
        /// part of the ISerializable interface
        /// </summary>
        /// <param name="info">The serialization info</param>
        /// <param name="ctxt">The streaming context</param>
        public override void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("StreetInfo", Street);
            info.AddValue("ZipInfo", Zip);
            info.AddValue("CityInfo", City);
            base.GetObjectData(info, ctxt);
        }
    }
}
